package com.mccken.practice.top100.Top_1$20.Top_22;

import java.util.ArrayList;
import java.util.List;

import com.mccken.practice.top100.ListNode;

/**
 * @program: mccken-collect
 * @description:
 * @author: mccken
 * @create: 2024-01-24 14:12
 **/
public class IsPalindrome1 {

	// 将链表中节点的值存储到数组中，再在数组上进行判断是否回文串
	public boolean isPalindrome1(ListNode head) {
		List<Integer> vals = new ArrayList<>();
		ListNode curr = head;
		while (curr != null) {
			vals.add(curr.val);
			curr = curr.next;
		}

		// 使用双指针判断
		int left = 0;
		int right = vals.size() - 1;
		while (left < right) {
			if (!vals.get(left).equals(vals.get(right))) {
				return false;
			}
			left++;
			right--;
		}
		return true;
	}

}
